//
//  HotDetail.m
//  Streaming
//
//  Created by 官琛 on 15-6-22.
//  Copyright (c) 2015年 liuxun. All rights reserved.
//

#import "HotDetail.h"

@implementation HotDetail


-(instancetype)initWithFrame:(CGRect)frame newsId:(NSInteger)nsewID
{
    self = [super initWithFrame:frame];
    if (self) {
        self.newsId = nsewID;
        [self creatView];
        }
    return self;
}

-(void)creatView
{
     [self afnGetRequest];
    
    self.webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 50, WIDTH, HEIGHT)];
    self.webView.backgroundColor = [UIColor whiteColor];
    [self.webView setScalesPageToFit:YES];
    self.webView.delegate= self;
    [self addSubview:self.webView];
   
  

    
    self.title1 = [[UILabel alloc]initWithFrame:CGRectMake(10, -40, WIDTH, 30)];
//    self.title1.backgroundColor = [UIColor cyanColor];
    self.title1.font = [UIFont boldSystemFontOfSize:20];
    [self.webView.scrollView addSubview:self.title1];
    [_title1 release];
    
    self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, -15, WIDTH, 20)];
    self.nameLabel.font = [UIFont systemFontOfSize:10];
    [self.webView.scrollView addSubview:self.nameLabel];
    [_nameLabel release];
    
    self.label = [[UILabel alloc]initWithFrame:CGRectMake(290, -15, WIDTH, 20)];
    self.label.font = [UIFont systemFontOfSize:10];
    [self.webView.scrollView addSubview:self.label];
    [_label release];
    
    self.HUD = [MBProgressHUD showHUDAddedTo:self.webView animated:YES];
    self.HUD.labelText = @"正在加载中";
    [self.HUD show:YES];
    [_HUD autorelease];
}

-(void)afnGetRequest
{
    
    
    AFNetworkReachabilityManager *netWorkManager = [AFNetworkReachabilityManager sharedManager];
    NSString *url_string = [NSString stringWithFormat:@"http://api.m.mtime.cn/News/Detail.api?newsId=%ld",self.newsId];
    
    
    //[NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];  代表支持所有的接口类型
    AFHTTPRequestOperationManager* manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"application/x-javascript",@"text/html",nil];
    
  
    
    
    [manager GET:url_string parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        [netWorkManager stopMonitoring];
//        NSLog(@"使用AFN进行get请求 ===  %@",responseObject);
        self.title1.text = [responseObject objectForKey:@"title"];
//        self.webView = [responseObject objectForKey:@"content"];
        [self.webView loadHTMLString:[responseObject objectForKey:@"content"] baseURL:nil];
        self.nameLabel.text = [responseObject objectForKey:@"time"];
        self.label.text = [NSString stringWithFormat:@"来自%@", [responseObject objectForKey:@"source"]];
        [self.HUD hide:YES];
        
        
        
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        NSLog(@"失败==== %@",error);
        [self.HUD hide:YES];
    }];
    
}



@end
